package com.hellojava.service;

import com.hellojava.dto.SysUserDto;
import com.hellojava.entity.SysUser;
import com.hellojava.jpa.CommonRepository;
import com.hellojava.jpa.SysRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dengjihai
 * @create 2017-11-16
 **/
@Service
public class SysUserService {

    @Autowired
    SysRepository sysRepository;

    @Autowired
    CommonRepository commonRepository;

    @Transactional(rollbackFor = Exception.class)
    public String save(String name,String pass){
        SysUser sysUser = new SysUser(name,pass);
        return sysRepository.save(sysUser).getId();
    }

    public List<SysUserDto>  getUserList(){
        Map<String,Object> map = new HashMap<>();
        map.put("loginName","dengjihai");
        List<SysUserDto> sysUserDtos=commonRepository.findNativeSQL(sql,map,SysUserDto.class);
        return sysUserDtos;
    }

    String sql ="select login_name,login_pass from sys_user where login_name=:loginName ";


}
